﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Data.Linq.Mapping;
using System.Linq;
using ALiteTeam.PackageTracer.Core;
using ALiteTeam.PackageTracer.Core.Impl;

namespace ALiteTeam.PackageTracer.Data
{
    [Table]
    public class DeliveryOrder : PropertyChangeBase
    {
        private IDeliveryOperate _DeliveryOp;

        public DeliveryOrder()
        {
            this.DeliveryOrderID = Guid.NewGuid();
            this._DeliveryOp = DeliveryDataOp.Instance;
        }

        private Guid mDeliveryOrderID;
        /// <summary>
        /// 该条记录ID
        /// </summary>
        [Column(IsPrimaryKey = true, IsDbGenerated = true, CanBeNull = false, AutoSync = AutoSync.OnInsert)]
        public Guid DeliveryOrderID
        {
            get { return mDeliveryOrderID; }
            set
            {
                if (mDeliveryOrderID != value)
                {
                    this.NotifyPropertyChanging(p => p.DeliveryOrderID);
                    mDeliveryOrderID = value;
                    this.NotifyPropertyChanged(p => p.DeliveryOrderID);
                }
            }
        }

        private Guid mDeliveryID;
        /// <summary>
        /// 快递公司ID
        /// </summary>
        [Column]
        public Guid DeliveryID
        {
            get { return mDeliveryID; }
            set
            {
                if (mDeliveryID != value)
                {
                    this.NotifyPropertyChanging(p => p.DeliveryID);
                    mDeliveryID = value;
                    this.NotifyPropertyChanged(p => p.DeliveryID);
                }
            }
        }

        private string mDeliveryName;
        public string DeliveryName
        {
            get
            {
                if (string.IsNullOrEmpty(mDeliveryName) == true)
                {
                    var delivery = this._DeliveryOp.DeliveryResource.Deliveries.Where(e => e.ID == this.DeliveryID).FirstOrDefault();
                    mDeliveryName = delivery.DisplayName;
                }

                return mDeliveryName;
            }
        }


        private string mOrderNo;
        /// <summary>
        /// 运单号
        /// </summary>
        [Column]
        public string OrderNo
        {
            get { return mOrderNo; }
            set
            {
                if (mOrderNo != value)
                {
                    this.NotifyPropertyChanging(p => p.OrderNo);
                    mOrderNo = value;
                    this.NotifyPropertyChanged(p => p.OrderNo);
                }
            }
        }

        private string mTitle;
        /// <summary>
        /// 标题
        /// </summary>
        [Column]
        public string Title
        {
            get { return mTitle; }
            set
            {
                if (mTitle != value)
                {
                    this.NotifyPropertyChanging(p => p.Title);

                    mTitle = value;
                    this.NotifyPropertyChanged(p => p.Title);
                }
            }
        }

        private DateTime mAddDateTime;
        /// <summary>
        /// 该条记录加入时间
        /// </summary>
        [Column]
        public DateTime AddDateTime
        {
            get { return mAddDateTime; }
            set
            {
                if (mAddDateTime != value)
                {
                    this.NotifyPropertyChanging(p => p.AddDateTime);
                    mAddDateTime = value;
                    this.NotifyPropertyChanged(p => p.AddDateTime);
                }
            }
        }

        private bool mIsAutoRefresh;
        /// <summary>
        /// 是否允许自动刷新
        /// </summary>
        [Column]
        public bool IsAutoRefresh
        {
            get { return mIsAutoRefresh; }
            set
            {
                if (mIsAutoRefresh != value)
                {
                    this.NotifyPropertyChanging(p => p.IsAutoRefresh);
                    mIsAutoRefresh = value;
                    this.NotifyPropertyChanged(p => p.IsAutoRefresh);
                }
            }
        }

        private double mRefreshDuration;
        /// <summary>
        /// 自动刷新时间间隔
        /// </summary>
        [Column]
        public double RefreshDuration
        {
            get { return mRefreshDuration; }
            set
            {
                if (mRefreshDuration != value)
                {
                    this.NotifyPropertyChanging(p => p.RefreshDuration);
                    mRefreshDuration = value;
                    this.NotifyPropertyChanged(p => p.RefreshDuration);
                }
            }
        }

        private string mSummary;
        /// <summary>
        /// 摘要信息
        /// </summary>
        [Column]
        public string Summary
        {
            get { return mSummary; }
            set
            {
                if (mSummary != value)
                {
                    this.NotifyPropertyChanging(p => p.Summary);
                    mSummary = value;
                    this.NotifyPropertyChanged(p => p.Summary);
                }
            }
        }

        private string mDetails;
        /// <summary>
        /// 明细信息
        /// </summary>
        [Column]
        public string Details
        {
            get { return mDetails; }
            set
            {
                if (mDetails != value)
                {
                    this.NotifyPropertyChanging(p => p.Details);
                    mDetails = value;
                    this.NotifyPropertyChanged(p => p.Details);
                }
            }
        }

        private DateTime? mLastSummaryUpdatedTime;
        /// <summary>
        /// 最后一次摘要信息更新时间
        /// </summary>
        [Column(CanBeNull = true)]
        public DateTime? LastSummaryUpdatedTime
        {
            get { return mLastSummaryUpdatedTime; }
            set
            {
                if (mLastSummaryUpdatedTime != value)
                {
                    this.NotifyPropertyChanging(p => p.LastSummaryUpdatedTime);
                    mLastSummaryUpdatedTime = value;
                    this.NotifyPropertyChanged(p => p.LastSummaryUpdatedTime);
                }
            }
        }

        private DateTime? mLastDetailsUpdatedTime;
        /// <summary>
        /// 最后一次摘要信息更新时间
        /// </summary>
        [Column(CanBeNull = true)]
        public DateTime? LastDetailsUpdatedTime
        {
            get { return mLastDetailsUpdatedTime; }
            set
            {
                if (mLastDetailsUpdatedTime != value)
                {
                    this.NotifyPropertyChanging(p => p.LastDetailsUpdatedTime);
                    mLastDetailsUpdatedTime = value;
                    this.NotifyPropertyChanged(p => p.LastDetailsUpdatedTime);
                }
            }
        }
    }
}
